package com.freesky.web.portal.controller;

import com.freesky.common.dao.entity.Order;
import com.freesky.common.utils.reponse.JSONResponse;
import com.freesky.common.vo.VOOrder;
import com.freesky.common.vo.VOOrderInfo;
import com.freesky.common.vo.VOThanks;
import com.freesky.web.portal.reomte.OrderRemote;
import com.netflix.discovery.converters.Auto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


/**
 * @author Freesky
 */
@RestController
@Api(description = "订单")
public class OrderController {
    @Autowired
    private OrderRemote orderRemote;

    @ApiOperation(value = "获得用户所有订单")
    @GetMapping(value = "/order/member/list")
    public JSONResponse getMemberOrderList(
            @RequestParam(value = "userId") String userId,
            @RequestParam(value = "page", defaultValue = "1") int page,
            @RequestParam(value = "size", defaultValue = "5") int size) {

        return orderRemote.getMemberOrderList(userId, page, size);
    }

    @GetMapping(value = "/order/detail")
    @ApiOperation(value = "通过id获取订单")
    public JSONResponse getOrderById(@RequestParam(value = "orderId")String orderId){
        return orderRemote.getOrderById(orderId);
    }

    @GetMapping(value = "/order/member/detail")
    @ApiOperation(value = "通过id获取订单")
    public JSONResponse getOrder(String orderId){
        return orderRemote.getOrder(orderId);
    }

    @PostMapping(value = "/order/member/add")
    @ApiOperation(value = "创建订单")
    public JSONResponse addOrder(@RequestBody VOOrderInfo orderInfo){
        return orderRemote.addOrder(orderInfo);
    }

    @PostMapping(value = "/order/member/cancel")
    @ApiOperation(value = "取消订单")
    public JSONResponse cancelOrder(@RequestBody VOOrder order){
        return orderRemote.cancelOrder(order);
    }

    @GetMapping(value = "/order/member/del")
    @ApiOperation(value = "删除订单")
    public JSONResponse delOrder(String orderId){
        return orderRemote.delOrder(orderId);
    }

    @PostMapping(value = "/order/member/pay")
    @ApiOperation(value = "支付订单")
    public JSONResponse payOrder(@RequestBody Order order){
        return  orderRemote.payOrder(order);
    }
}
